package com.woniuxy.ptapp.app.controller;
import com.woniuxy.commons.util.BeanCopyUtil;
import com.woniuxy.commons.util.Result;
import com.woniuxy.ptapp.client.ClassesInfoClient;
import com.woniuxy.ptapp.client.param.ClassesParam;
import com.woniuxy.ptapp.common.exception.EnumExceptionCode;
import com.woniuxy.ptapp.common.exception.ParamException;
import com.woniuxy.ptapp.common.exception.WoniuxyException;
import com.woniuxy.ptapp.infra.model.ClassesInfo;
import com.woniuxy.ptapp.service.ClassesInfoService;
import io.swagger.annotations.Api;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wangdong
 * @since 2022-07-30
 */

@RestController
public class ClassesInfoController implements ClassesInfoClient {
    @Resource
    ClassesInfoService classesInfoService;


    @Override
    public Result upClasses(ClassesParam classesParam) {
        ClassesInfo classesInfo = BeanCopyUtil.copyObject(classesParam, ClassesInfo.class);
        boolean save = classesInfoService.save(classesInfo);
        if(!save){
            throw new WoniuxyException(EnumExceptionCode.UpClassesFail.getCode(),EnumExceptionCode.UpClassesFail.getMessage());
        }
        return Result.getInstance().setCode(200).setMsg("新增课程成功");
    }

    @Override
    public Result<Boolean> checkClaessId(Integer id) {
        if(null==id||id<=0){
            throw new ParamException();
        }
        Boolean b = classesInfoService.checkClaessId(id);
        return Result.getInstance(boolean.class).setMsg("查询课程成功").setData(b).setCode(200);
    }




}

